/**
 * 打包
 * Created by dr2009 on 2017/2/21.
 */
const path = require('path');
const webpack = require("webpack");
const webpackMerge = require('webpack-merge');
const ChunkManifestPlugin = require("chunk-manifest-webpack-plugin");
const WebpackChunkHash = require("webpack-chunk-hash");

const commonConfig = require('./base.js');

module.exports = function (env) {
    return webpackMerge(commonConfig(), {
        output: {
            path: path.join(__dirname, "../dist"),
            filename: '[name].[chunkhash:8].js',
            chunkFilename: '[id].[chunkhash:8].js'
        },
        plugins: [
            new webpack.HashedModuleIdsPlugin(),
            new WebpackChunkHash(),
            new ChunkManifestPlugin({
                filename: "chunk-manifest.json",
                manifestVariable: "webpackManifest"
            }),
            // 作用不知道
            new webpack.LoaderOptionsPlugin({
                minimize: true,
                debug: false
            }),
            // 压缩
            new webpack.optimize.UglifyJsPlugin({
                sourceMap: true,
                compress: {
                    warnings: true
                }
            }),
            new webpack.DefinePlugin({
                'process.env.NODE_ENV': JSON.stringify('production'),
                'XSite_ENV': JSON.stringify(env), // test | gray | prod
            })
        ]
    })
};